package com.motorhome.manage.controller;

import com.motorhome.base.util.Result;
import com.motorhome.manage.domain.ManageUser;
import com.motorhome.manage.service.MainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: John
 */
@Controller
@RequestMapping("/main")
public class MainController {

    @Autowired
    private MainService mainService;

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index() {
        return "main/index";
    }

    @RequestMapping(value = "/updatePass")
    public String updatePass() {
        return "passwd/passwd";
    }

    @RequestMapping(value = "/savePass")
    public @ResponseBody String savePass(HttpServletRequest request,
                                         String password, String password1, String password2) {
        ManageUser manageUser = (ManageUser)request.getAttribute("manageUser");
        Result result = mainService.savePass(manageUser, password, password1, password2);
        return result.toJson();
    }

}
